package com.github.ybq.android.spinkit;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.widget.TextView;

import com.github.ybq.android.spinkit.sprite.Sprite;

/**
 * Created by zhangyingjie on 2019-11-22
 *
 * @function
 */
public class Loading {
    private Context context;
    private LoadingDialog mloading;
    private Sprite sprite;

    public Loading(Context context,String content) {
        this(context,null,content);
    }

    public Loading(Context context, Sprite sprite,String content) {
        this.context = context;
        this.sprite = sprite;
        mloading = new LoadingDialog(content);
    }


    public void start(){
        if (mloading != null) {
            mloading.show();
        }
    }

    public void end(){
        if (mloading != null) {
            mloading.dismiss();
        }
    }

    /**
     * @author http://blog.csdn.net/finddreams
     * @Description:自定义对话框
     */
   private class LoadingDialog extends Dialog {

        private SpinKitView spinKitView;
        private TextView mLoadingTv;

        private LoadingDialog(String content) {
//		setCanceledOnTouchOutside(false);
            super(context, R.style.CustomProgressDialog);
            this.setContentView(R.layout.loadingdialog);
            this.getWindow().getAttributes().gravity = Gravity.CENTER;
            this.setCanceledOnTouchOutside(false);
            spinKitView = findViewById(R.id.spin_kit);
            if (sprite != null) {
                spinKitView.setIndeterminateDrawable(sprite);
            }
            mLoadingTv = (TextView) findViewById(R.id.name);
            if (content != null) {
                mLoadingTv.setText(content);
            }
        }
        public void setContent(String str) {
            mLoadingTv.setText(str);
        }

    }

}
